// pages/discover/discover.js
const app = getApp()
const url = app.basicsUrl();

Page({
  data: {
    hongBaoTimes: [],
    list: [],
    none: true,
    inquirylist: [],
    loadall: true,
    page: 1,
    pageCount: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getInquireList(1)
  },

  /**
   * getInquireList分页方法
   */
  getInquireList: function (page) {
    var that = this;
    var params = {};
    params['page'] = page;
    params['size'] = 10;
    wx.request({
      url: url + 'square',
      data: params,
      success: res => {
        if (res.data.code == 200) {
          var hongBaoTimes = res.data.data.squareDtoList;
          if (hongBaoTimes) {
            for (var i = 0; i < hongBaoTimes.length; i++) {
              hongBaoTimes[i]['hongBao']['createTime'] = app.timeFormat(hongBaoTimes[i]['hongBao']['createTime'] / 1000)
              hongBaoTimes[i]['user']['name'] = decodeURI(hongBaoTimes[i]['user']['name'])
            }
            var list = res.data.data.squareDtoList;
            var olist = that.data.inquirylist;
            for (var i = 0; i < list.length; i++) {
              olist.push(list[i]);
            }
            that.setData({
              inquirylist: olist,
              pageCount: res.data.data.pages
            })
          } else {
            that.setData({
              none: false
            })
          }
        } else {
          wx.showLoading({
            title: res.data.msg,
          })
          setTimeout(function () {
            wx.hideLoading()
          }, 1000)
        }
      }
    })
  },
  
  /**
   * 点击发现列表
   */
  bindhongBao: function (e) {
    var that = this;
    wx.navigateTo({
      url: '/pages/games/games?hongBaoId=' + e.currentTarget.dataset.hongbaoid
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var page=++that.data.page;
    that.setData({
      none: true
    });
    if (that.data.page <= that.data.pageCount) {
      that.getInquireList(page);
      that.setData({
        page: page,
        size: 10
      });
    } else if (that.data.page = that.data.pageCount) {
      that.setData({
        loadall: false
      });
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
})